from typing import Optional, Dict, Any
import jwt
from intelli_port.commons.config import load_settings


def decode_token(token: str) -> Optional[Dict[str, Any]]:
    s = load_settings()
    sec = getattr(s, "jwt_secret", "")
    alg = getattr(s, "jwt_alg", "HS256")
    if not sec:
        return None
    try:
        return jwt.decode(token, sec, algorithms=[alg])
    except Exception:
        return None